import { IADAble, ADConfig } from "./IADAble";
import { AnalyticsAble, IAnalyticsSender } from "./IAnalyticsAble";
import { IDevice } from "./IDevice";
import { ILoginAble } from "./ILoginAble";
import { IPayAble } from "./IPayAble";
import { IPublisher } from "./IPublisher";
import { IRecordAble } from "./IRecordAble";
import { IShareAble } from "./IShareAble";


/*
@name: PublisherManager
@desc: 多平台管理，集成平台的登录，支付等功能。类似国内外的微信小游戏、小米app、华为快应用等
@author: timoo
@date: 2022/11/26
*/
export abstract class IPublisherManager {
    private static PUBLISHER_TYPE_OF_DEVELOP:string = "Develop";
    private _publisher:IPublisher;
    private _ad:IADAble;
    private _analytics:AnalyticsAble;
    private _login:ILoginAble;
    private _pay:IPayAble;
    private _record:IRecordAble;
    private _share:IShareAble;
    private _device:IDevice;

    public abstract enable():void;
    /**
     * 初始化平台
     * @param publisherId 平台ID，0保留为DEVELOP
     * @param publisher 
     */
    protected setPublisher(type:string, publisher:{new ():IPublisher}):void{
        this._publisher = new publisher().init(type);
        console.log(`平台:[${type}]初始化成功`);
    }
    
    /**
     * 获取平台类实例
     * @return IPublisher
     */
    public get publisher():IPublisher{
        return this._publisher;
    }

    protected setDevice(type:string, device:{new ():IDevice}):void {
        this._device = new device().init(type);
    }
    public get device():IDevice{
        return this._device;
    }

    public get type():string{
        return this._publisher.type;
    }

    public get appId():string{
        return this._publisher.appId;
    }

    public get appVersion():string{
        return this._publisher.appVersion;
    }

    public isDebug():boolean{
        return this.type == IPublisherManager.PUBLISHER_TYPE_OF_DEVELOP;
    }

    public isTarget(type:string):boolean{
        return this.type == type;
    }

    protected enableAdAble(type:string, ad:{new ():IADAble}, config:ADConfig):void{
        this._ad = new ad().init(type, config);
    }

    public get ad():IADAble{
        return this._ad
    }

    /**
     * 启用事件统计
     * @param senders 统计发送器，允许多个。
     * @param debugMode 调试模式，是否打印日志信息，默认为false
     * @param analytics 事件统计的数据处理器，默认为app.AnalyticsAble
     */
    protected enableAnalytics(senders:IAnalyticsSender[], debugMode:boolean=false, analytics:{new ():AnalyticsAble}=AnalyticsAble):void{
        this._analytics = new analytics().init(senders, debugMode);
    }
    public get analytics():AnalyticsAble{
        return this._analytics;
    }

    protected enableLogin(type:string, login:{new ():ILoginAble}):void{
        this._login = new login().init(type);
    }
    public get login():ILoginAble{
        return this._login;
    }

    protected enablePay(type:string, pay:{new ():IPayAble}):void{
        this._pay = new pay().init(type);
    }
    public get pay():IPayAble{
        return this._pay;
    }

    protected enableRecord(type:string, record:{new ():IRecordAble}):void{
        this._record = new record().init(type);
    }
    public get record():IRecordAble{
        return this._record;
    }

    protected enableShare(type:string, share:{new ():IShareAble}):void{
        this._share = new share().init(type);
    }
    public get share():IShareAble{
        return this._share;
    }
}
